<template>
  <div class="tx">
    <el-dialog
      :visible.sync="dialogVisible"
      width="30%">
      <div class="tx-header">
        <span>{{pageText}}</span>
      </div>
      <ul class="tx-form">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="ruleForm.name" disabled></el-input>
          </el-form-item>
          <el-form-item label="离职日期" prop="dimissionTime">
            <el-date-picker
              v-model="ruleForm.dimissionTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="离职原因" prop="dimissionCause">
            <el-select v-model="ruleForm.dimissionCause" placeholder="请选择离职原因">
              <el-option label="个人原因" value="geren"></el-option>
              <el-option label="公司原因" value="gongsi"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="离职备注" prop="dimissionRemark">
            <el-input
              type="textarea"
              :rows="5"
              resize='none'
              maxlength='200'
              placeholder="请输入内容"
              v-model="ruleForm.dimissionRemark">
            </el-input>
          </el-form-item>
        </el-form>
      </ul>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" class="red-b" @click="submit('ruleForm')">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template> 

<script>
export default {
  props:['dialogVisible','changePopping','isForbiddenInput','pageText'],
  data (){
    return {
      ruleForm: {
        name: '',//姓名
        dimissionTime:'',//离职日期
        dimissionCause:'',//离职原因
        dimissionRemark:'',//离职备注
      },
      rules:{
        dimissionTime: [
          { required: true, message: '请输入离职日期', trigger: 'change' },
        ],
        dimissionCause: [
          { required: true, message: '请输入离职原因', trigger: 'change' },
        ],
      },
    }
  },
  mounted(){
    console.log(this.$parent,'this指向')
  },
  methods:{
    //提交按钮
    submit(formName){
      this.$refs[formName].validate((valid) => {
          if (valid) {
            //判断是从办理离职页面进来的还是修改离职信息进来的
            if(this.pageText == '办理离职'){
              let {name,dimissionTime,dimissionCause,dimissionRemark} = {...this.ruleForm}
              this.changePopping(false,true)
            }else{

            }
          } else {
            this.$message.error('请按要求填写')
            return false;
          }
        });
    },
    //取消按钮
    cancel(){
      if(this.pageText == '办理离职'){
        this.changePopping(false,this.isForbiddenInput)
      }else{
        this.changePopping(false)
      }
      
    },
  },
}
</script>

<style scoped>
  .tx /deep/ .el-dialog__header{
    display: none;
  }
  .tx-header{
    height: 42px;
    line-height: 42px;
    background: #EEEEEE;
    border-radius: 10px 10px 0px 0px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333333;
    text-align: center;
    margin-bottom: 50px;  
  }
  .tx /deep/ .el-dialog__body{
    padding: 0;
  }
  .tx-form{
    padding: 0 70px 0 70px;
  }
  .tx /deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner{
    width: 100%;
  }
  .tx /deep/ .el-select{
    width: 100%;
  }
  .tx /deep/ .el-select-dropdown__item.hover{
    background: #ff0000;
    color:#fff;
  }
  .tx /deep/ .el-dialog__footer{
    text-align: center;
    margin-bottom: 20px;
  }
  .tx /deep/ .el-button--medium{
    width: 23%;
    height: 38px;
    border-radius: 19px;
  }
  .tx /deep/ .el-button--primary{
    margin-right: 20px;
    border: none;
  }
</style>